

<include file="public@header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('ticketindex/index')}">兑换券管理</a></li>
        <li><a href="{:url('ticketindex/add')}">添加兑换券</a></li>
    </ul>

    <form class="well form-inline margin-top-20" method="get" >

        名称:
        <input type="text" class="form-control" id="name" style="width: 120px;"  placeholder="请输入用户名">


        状态:
        <select class="form-control" name="category" id="status" style="width: 140px;">
            <option value=''>全部</option>
            <option value='1'>下架</option>
            <option value='2'>上架</option>
        </select> &nbsp;&nbsp;

        <input type="button" id="selectval" class="btn btn-primary" value="搜索" />


        <a class="btn btn-danger" href="{:url('ticketindex/index')}">清空</a>
    </form>

    <table class="table table-hover table-bordered">

        <table class="layui-hide" id="test" lay-filter="test"></table>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
<!--                <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
<!--                <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
<!--                <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
            </div>
        </script>
        <script type="text/html" id="barDemo">

            <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="zengsong">赠送</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="duihuan">兑换</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>

        <!--    自定义    -->
        <script type="text/html" id="titleTpl">
            {{#  if(d.status == 1){ }}
            上架
            {{#  } else { }}
            下架
            {{#  } }}
        </script>
        <script type="text/html" id="titleTpl1">
            {{#  if(d.top ==1){ }}
            展示
            {{#  } else { }}
            隐藏
            {{#  } }}
        </script>

        <script type="text/html" id="titleTpl2">
            <a class="layui-btn layui-btn-xs" lay-event="inuser">{{d.inuser}}</a>
        </script>
        <script type="text/html" id="titleTpl3">
            <a class="layui-btn layui-btn-xs" lay-event="userzs">{{d.zs}}</a>
        </script>
        <script>



            layui.use('table', function(){
                var table = layui.table;


                var tableIns =table.render({
                    elem: '#test' ,
                    url:'index',
                    method: 'post',
                    toolbar: '#toolbarDemo',
                    title: '用户数据表',
                    // totalRow: true ,
                    cols: [[

                        {field:'id', title:'ID', width:80, fixed: 'left'}
                        ,{field:'name', title:'名称',edit: 'text'}
                        ,{field:'integrate', title:'兑换积分', }
                        ,{field:'', title:'状态', templet: '#titleTpl'}
                        ,{field:'', title:'首页', templet: '#titleTpl1'}
                        ,{field:'', title:'持有', templet: '#titleTpl2'}
                        ,{field:'', title:'使用', templet: '#titleTpl3'}
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                    ]]
                    ,page: true
                });


                $("#selectval").click(function (){

                    var name=$("#name").val();
                    var status=$("#status").val();

                    tableIns.reload({
                        where: { status: status,name:name} ,
                        page: { curr: 1  }
                    });

                })

                //表格工具行事件
                table.on('tool(test)', function(obj){
                    var data = obj.data;
                    //console.log(obj)
                    if(obj.event === 'del'){
                        layer.confirm('真的删除行么', function(index){
                            $.ajax({
                                url:'delete',
                                data:{'id':data.id},
                                type:'post',
                                success:function (ret){

                                    layer.msg(ret.msg)
                                    obj.del();
                                    layer.close(index);
                                }
                            })
                        });
                    } else if(obj.event === 'edit'){
                        var curl='edit?id='+data.id


                        console.log(curl);
                        location.href=curl;
                    }else if(obj.event === 'inuser'){

                        var index=layer.open({
                            type: 2,
                            title:'参与信息',
                            area: ['1200px', '600px'],
                            content: 'inuser?id='+data.id,
                            success:function (){
                                // var index = parent.layer.getFrameIndex(window.name);
                                // parent.layer.close(index);
                            },
                            end: function() {

                                console.log('关闭页面');
                                location.reload();
                            },
                        });


                    }else if(obj.event === 'userzs'){

                        var index=layer.open({
                            type: 2,
                            title:'转赠信息',
                            area: ['1200px', '600px'],
                            content: 'userzs?id='+data.id,
                            success:function (){
                                // var index = parent.layer.getFrameIndex(window.name);
                                // parent.layer.close(index);
                            },
                            end: function() {

                                console.log('关闭页面');
                                location.reload();
                            },
                        });

                    } else if(obj.event === 'zengsong'){


                        var index=layer.open({
                            type: 2,
                            title:'转赠信息',
                            area: ['1000px', '600px'],
                            content: 'zengsong?id='+data.id,
                            success:function (){
                                // var index = parent.layer.getFrameIndex(window.name);
                                // parent.layer.close(index);
                            },
                            end: function() {

                                console.log('关闭页面');
                                location.reload();
                            },
                        });

                    }else if(obj.event === 'duihuan'){

                        var index=layer.open({
                            type: 2,
                            title:'兑换信息',
                            area: ['1000px', '600px'],
                            content: 'duihuan?id='+data.id,
                            success:function (){
                                // var index = parent.layer.getFrameIndex(window.name);
                                // parent.layer.close(index);
                            },
                            end: function() {

                                console.log('关闭页面');
                                location.reload();
                            },
                        });

                    }
                });


            });
        </script>


    </table>

</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>